package com.zxy.springbootactivemq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangxuyuan
 * @version 1.0
 * @date 2020/11/22
 */
@Service
public class JmsSender {


    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private JmsTemplate jmsTemplate;

    public void sendObject(MyMessage myMessage)
    {
        //传输一个自定义的Object
        jmsMessagingTemplate.convertAndSend("springboot",myMessage);
    }
    //事务支持
    @Transactional(rollbackFor = Exception.class)
    public void sendBatchMessage()
    {
        for(int i=0;i<10;i++)
        {
            jmsMessagingTemplate.convertAndSend("queue1","springboot jmssender +"+i);
            if(i==9)
            {
                int a=i/0;
            }
        }
    }


}
